﻿Imports TVDBSharp
Public Class TheTVDB

    Dim _tvdb As TVDBSharp.TVDB
    Const APIKey As String = "9151D773D4AE2C2D"

    Public Sub New()

        _tvdb = New TVDBSharp.TVDB(APIKey)

    End Sub

    Public Function SearchSeries(ByVal _querystring As String, ByVal _seasonnumber As Integer, ByVal _episodenumber As Integer) As String

        Dim _rt As String = String.Empty

        Debug.WriteLine("TVDB Searchstring: {0}", _querystring)

        For Each _searchstring In _querystring.Split(",")

            Dim _result As List(Of Models.Show)

            _result = _tvdb.Search(_searchstring, 1)

            Debug.WriteLine("Es wurden {0} Serien gefunden", _result.Count)

            For Each _series_result In _result

                Debug.WriteLine(_series_result.Name)

                If Not _series_result.Episodes.Count = 0 Then

                    For Each _episode In _series_result.Episodes

                        If _episode.SeasonNumber = _seasonnumber And _episode.EpisodeNumber = _episodenumber Then
                            _rt = String.Format("{0} - {1}", _series_result.Name, _episode.Title)
                        End If

                    Next

                Else
                    Debug.WriteLine("Keine Serien gefunden")
                End If

            Next

        Next

        Return _rt

    End Function



End Class
